let close = document.querySelector('.times');
let ad = document.querySelector('.beginning');

//关闭小广告
close.onclick = function () {
  ad.remove();
};

require.config({
  baseUrl: "../js/library", //基础路径
  paths: {
    jQuery: "jquery",
    axios: "axios",
  },
  // shim用于管理第三方插件的依赖 
  shim: {},
});
// 首页基础js实现
require(["jquery"], function ($) {


  $(".carousel-slide .list-group>.list-group-item").on("mouseover", function () {

    let index = $('.carousel-slide .list-group>.list-group-item').index(this)
    $('.carousel-slide .list-group .slide-right').eq(index).css("display", "block")
  })


  $(".carousel-slide .list-group>.list-group-item").on("mouseout", function () {


    let index = $('.carousel-slide .list-group>.list-group-item').index(this)
    $('.carousel-slide .list-group .slide-right').eq(index).css("display", "none");
  })

  $(".slide-right").on("mouseenter", function () {
    $(this).css("display", "block");
  });
  $(".slide-right").on("mouseleave", function () {
    $(this).css("display", "none");
  })


  $(".navbar-left>li:eq(0)").on(
    'mouseenter',
    function () {
      $('.firstli').slideDown(1000);

    }

  );
  $(".firstli").on(
    'mouseenter',
    function () {
      $('.firstli').css('display', 'block');

    }

  );
  $(".firstli").
  mouseleave(function () {
      $('.firstli').css("display", "none");
    }

  );
  $(".navbar-left>li:eq(0)").
  mouseleave(function () {
      $('.firstli').css("display", "none");
    }

  );

  $(".navbar-right>li:last>a").on(
    'mouseover',
    function () {
      $('.hidden-four').slideDown(1000).css("backgroundColor", "white");

    }

  );
  $(".hidden-four").on(
    'mouseover',
    function () {
      $('.hidden-four').css('display', 'block');

    }

  );
  $(".hidden-four").on(
    'mouseout',
    function () {
      $('.hidden-four').css("display", "none");
    }

  );
  $(".navbar-right>li:last>a").on(
    'mouseout',
    function () {
      $('.hidden-four').css("display", "none");
    }

  );
});

//左边固定定位的楼梯特效


require(["jquery"], function ($) {

  let winHeight = $(document).scrollTop();

  $(window).scroll(function () {
    let scrollY = $(document).scrollTop(); // 获取垂直滚动的距离，即滚动了多少

    if (scrollY > 700) { //如果滚动距离大于550px则隐藏，否则删除隐藏类
      $('.fixed-stairs').css('display', 'block');
    } else {
      $('.fixed-stairs').css('display', 'none');

    }


  });


  $('.fixed-stairs>li>a').on('click', function () {

    let id = $(this).attr('data-title');
    let elm = $('#' + id);

    let top = elm.offset().top;

    $('html').animate({
      scrollTop: top
    }, 800);
  });

  $(window).on('scroll', function () {
    let top = $(document).scrollTop();
    let _index = Math.round(top / 600);

    $('.fixed-stairs>li>a').removeClass('active').eq(_index).addClass('active');
  });



});

// axios页面渲染

require(["axios","jquery"], function (axios,$) {
  axios.get('../product/getItems').then((res) => {
      let data=res.data;
     
      let temp ="";
      data.forEach((elm)=>{
         let pic =JSON.parse(elm.picture);
         temp+=`<li class="item">
         <a href="../html/item.html?id=${elm.id}">
           <div class="p-img">
             <img src="../${pic[0].src}" alt="" />
           </div>
           <div class="p-title">
            ${elm.title}
           </div>
           <div class="p-price"><span class="yuan">￥</span>${elm.price}</div>
         </a>
       </li>`;
       $('.items').html(temp);
      });
    })
    .catch((err) => {
      console.log(err);
    });
});